package futbolfacil.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import junit.framework.Assert;

import futbolfacil.excepcion.DAOExcepcion;
import futbolfacil.modelo.Cliente;
import futbolfacil.modelo.ServicioAdicional;
import futbolfacil.negocio.AlmacenNegocio;
import futbolfacil.negocio.SeguridadNegocio;

/**
 * Servlet implementation class RegistrarServAdicServlet
 */
@WebServlet("/RegistrarServAdicServlet")
public class RegistrarServAdicServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarServAdicServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SeguridadNegocio neg = new SeguridadNegocio();		
		ServicioAdicional objServAdi = new ServicioAdicional();
		
		objServAdi.setNomserv(request.getParameter("txtDesc").trim());
		objServAdi.setStock(Integer.valueOf(request.getParameter("txtCantidad")));
		objServAdi.setPrecio(Double.valueOf(request.getParameter("txtPrecio")));
		objServAdi.setServcar(request.getParameter("txtCaract"));

		try {
			neg.insertarServicio(objServAdi);
			System.out.println("Se registro exitosamente al Servicio!");
		} catch (DAOExcepcion e) {
			//Assert
			//Assert.fail("Error al insertar: " + e.getMessage());
		}
		
		RequestDispatcher rd = request.getRequestDispatcher("frmServAdicional.jsp");
		rd.forward(request, response);
	}

}
